<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleAdd">
          新增
        </a-button>
        <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls">
          导出
        </a-button>
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts" name="ERP-procurement" setup>
  import { BasicTable, TableAction, ActionItem } from '/@/components/Table';
  import { columns } from './order.data';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { getExportUrl } from '/@/api/ERP/procurement'
  // 列表页面公共参数、方法
  const { tableContext, onExportXls } = useListPage({
    designScope: 'order-template',
    tableProps: {
      title: '采购订单',
      columns: columns,
      formConfig: {
        schemas: [],
      },
    },
    exportConfig: {
      name: '采购订单',
      url: getExportUrl,
    },
    importConfig: {
      url: '',
    },
  });
  const [registerTable] = tableContext;
  /**
   * 操作栏
   */
  function getTableAction(record): ActionItem[] {
    return [
      {
        label: '编辑',
        onClick: handleEdit.bind(null, record),
        // ifShow: () => hasPermission('system:user:edit'),
      },
    ];
  }
  /**
   * 新增事件
   */
  function handleAdd() {
    console.log('新增事件');
  }
  /**
   * 编辑事件
   */
  async function handleEdit(record: Recordable) {
    console.log(record, 'record');
  }
</script>
